<?php
    $item_per_page = 20;
    
    if(!empty($_POST["page"])){
        $page_number = filter_var($_POST["page"], FILTER_SANITIZE_NUMBER_INT, FILTER_FLAG_STRIP_HIGH);
        //echo "page number ".$_POST["page"];
    }else {
        $page_number = 0;
        //echo "page number ".$page_number;
    }
    
    //throw HTTP error if page number is not valid
    if(!is_numeric($page_number)){
        header('HTTP/1.1 500 Invalid page number!');
        exit();
    }

    //get current starting point of records
    //echo "</br> page number ".$page_number;
    //echo "</br> item per page ".$item_per_page;
    $position = ($page_number * $item_per_page);
    //echo "</br> position ".$position;
    
    if(!empty($_GET['cat'])){
        $cat_id = round($_GET['cat']);
        $sql1 = "SELECT * FROM app t1 INNER JOIN category_app t2 ON t1.id = t2.app_id where t2.category_id=".$cat_id." LIMIT $position, $item_per_page";
        
    }else{
        //echo "</br> in sql comment pos = ". $position." item = ".$item_per_page;
        $sql1 = "Select * from app LIMIT $position, $item_per_page";
        
    }
    include("../database/connection.php");
    $rs1 = mysqli_query($conn, $sql1);
    while($r1 = mysqli_fetch_assoc($rs1)){
?>
<script src="ratingfiles/ratings.js" type="text/javascript"></script>
<div class="item">
    
	<div class="item-icon">
    	<a alt="#" href="?mod=detail&idapp=<?php echo $r1['id']?>"><img src="img/app/<?php echo $r1['image']?>" /></a>
    </div>
    
    <div class="item-description">
        <span class="item-name"><?php if(strlen($r1['name']) > 20) echo substr($r1['name'],0,19)."..."; else echo $r1['name'];?></span><br/>
        <a class="item-download" href="<?php echo $r1['link']?>">Download</a>
        <div class="srtgs" id="rt_app_<?php echo $r1['id']?>"></div>
        <div class="info-wapper"><img src="img/ivers.png"/>&nbsp;<span><?php echo $r1['version']?></span><img src="img/iview.png"/>&nbsp;<span><?php echo $r1['view']?></span><img src="img/isize.png"/>&nbsp;<span><?php echo $r1['size']?></span></div>
    </div>
</div>


<?php
	}
?>

